#include "jobdetaildlg.h"
#include "ui_jobdetaildlg.h"

JobDetailDlg::JobDetailDlg(QString id,QList<DictData> sys_job_group,QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::JobDetailDlg)
{
    ui->setupUi(this);
    setWindowIcon(QPixmap(":/image/res/stm.jpg"));
    this->id = id;
    this->sys_job_group = sys_job_group;

    init();
}

JobDetailDlg::~JobDetailDlg()
{
    delete ui;
}

void JobDetailDlg::on_btn_close_clicked()
{
    close();
}

void JobDetailDlg::init()
{
    QByteArray *data = api.getById(id.toLongLong());
    QJsonObject obj = QJsonDocument::fromJson(*data).object();
    if(obj.value("code") == 200){
        Job job = Job::toJob(obj.value("data").toObject());
        ui->label_jobNum->setText(QString::number(job.jobId));
        QString group;
        for (int i = 0; i < sys_job_group.size(); ++i) {
            if(sys_job_group.at(i).dictValue == job.jobGroup){
                group = sys_job_group.at(i).dictLabel;
            }
        }
        ui->label_jobGroup->setText(group);
        ui->label_createTime->setText(job.createTime);
        ui->label_jobName->setText(job.jobName);
        ui->label_cronExpression->setText(job.cronExpression);
        ui->label_nextExecuteTime->setText(job.nextValidTime);
        ui->label_invokeTargetMethod->setText(job.invokeTarget);
        ui->label_jobStatus->setText(job.status == "0" ? "正常" : "失败");
        ui->label_isConcurrent->setText(job.concurrent == "0" ? "允许" : "禁止");
        QString policy;
        if(job.misfirePolicy == "0"){
            policy = "默认策略";
        }else if(job.misfirePolicy == "1"){
            policy = "立即执行";
        }else if(job.misfirePolicy == "2"){
            policy = "执行一次";
        }else if(job.misfirePolicy == "3"){
            policy = "放弃执行";
        }
        ui->label_invokePolicy->setText(policy);
    }
}

